---
title: "List Experiment Table"
output: pdf_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(knitr)
library(survey)
library(foreign)
library(car)
library(xtable)
mil_conf.df <- read.csv("~/Dropbox/Public_Conf_Mil/Data_and_code/mil_conf.csv")
```

```{r echo = FALSE}
source("~/Dropbox/Public_Conf_Mil/Data_and_code/PCM_cleaning.R")

milconf_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight,
    data = mil_conf.df
  )
```

```{r echo = FALSE}
Q41 <- matrix(NA, nrow = 4, ncol = 5)
Q41[1,1] <- svyby(~Q41D, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[2,1] <- svyby(~Q41D, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[3,1] <- svyby(~Q41D, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[4,1] <- svyby(~Q41D, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2]
Q41[1,2] <- svyby(~Q41E, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[2,2] <- svyby(~Q41E, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[3,2] <- svyby(~Q41E, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3]
Q41[4,2] <- svyby(~Q41E, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2]
Q41[,3] <- (Q41[,2] - Q41[,1]) * 100
Q41[1,4] <- svyby(~Q41A_a, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3] * 100
Q41[2,4] <- svyby(~Q41A_a, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3] * 100
Q41[3,4] <- svyby(~Q41A_a, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3] * 100
Q41[4,4] <- svyby(~Q41A_a, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2] * 100
Q41[,5] <- Q41[,4] - Q41[,3]
rownames(Q41) <- c("Democrat", "Independent", "Republican", "Overall")
colnames(Q41) <- c("Control", "Treatment", "True (%)", "Direct (%)", "Effect (%)")
Q41_tab <- xtable(Q41)
digits(Q41_tab) <- c(0,2,2,0,0,0)
align(Q41_tab) <- "rccccc"
```

```{r echo = FALSE, results = "asis"}
print(Q41_tab, comment = FALSE, size = "\\large")
```